/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.OneCommerceProject.controllers;

import com.OneCommerceProject.beans.UtilisateurFacade;
import com.OneCommerceProject.controllers.util.JsfUtil;
import com.OneCommerceProject.entities.Utilisateur;
import java.math.BigInteger;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;

import javax.faces.bean.SessionScoped;

import org.primefaces.event.FlowEvent;

/**
 *
 * @author Malek
 */
@ManagedBean(name = "registerController")
@SessionScoped
public class registerController {

    private Utilisateur user = new Utilisateur();
    @EJB
    private UtilisateurFacade utilisateurFacade;

    public Utilisateur getUser() {
        return user;
    }

    public void setUser(Utilisateur user) {
        this.user = user;
    }

    public String onFlowProcess(FlowEvent event) {
        return event.getNewStep();
    }

    public String Register() {
        try {
            user.setNbreachat(BigInteger.ZERO);
            user.setTypeclient("Inscrit");
            utilisateurFacade.create(user);
            user = new Utilisateur();
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("UtilisateurCreated"));
            return "/user/public.xhtml?faces-redirect=true";
        } catch (Exception e) {
//            JsfUtil.addErrorMessage("Le Login "+user.getLogin()+" existe déja");
            JsfUtil.addErrorMessage(e.getMessage());
            return null;
        }
    }
}
